﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GmUiCommonComponent.h"
#include "ILineEditDefinition.h"
#include "ICoordinateInputDefinition.h"

namespace gcmp
{
    class ILineEditEvent;
    class ICoordinateInputEventHandler;
    class IControlState;
    class ValidatorBase;

    class GM_UI_COMMON_COMPONENT_EXPORT CoordinateInputDefinition : public ICoordinateInputDefinition
    {
        friend class ICoordinateInputEventHandler;

    public:
        CoordinateInputDefinition(const std::wstring& id, const std::wstring& caption, LineEditInputType inputType = LineEditInputType::InputString);
        CoordinateInputDefinition(OwnerPtr<ILineEditDefinition> opDefinitionImpl);
        virtual ~CoordinateInputDefinition();
    public: //重载ICoordinateInputDefinition
        virtual LineEditInputType GetInputType() const override;
        virtual std::wstring GetText() const override;
        virtual bool SetText(const std::wstring& text) override;
        virtual bool IsEditingFinished() const override;
        virtual void SetIsEditingFinished(bool isEditingFinished) override;
        virtual ILineEditEvent* GetEvent() const override;
        virtual std::wstring GetId() const override;
        virtual std::wstring GetCaption() const override;
        virtual std::wstring GetTooltip() const override;
        virtual bool IsLock() const override;
    public:
        virtual void SelectAll();
        virtual void Clear();
        virtual std::wstring GetSelectedText() const;
        virtual ControlDefinitionType GetType() const;
        virtual bool IsEditing() const;
        virtual bool IsVisible() const;
        virtual bool IsEnabled() const;
        virtual bool SetEnabled(bool enabled);
        virtual bool SetVisible(bool visible);
        virtual bool SetValidator(OwnerPtr<ValidatorBase> pValidator);
        virtual ValidatorBase* GetValidator();
        bool SetCoordinateInputEventHandler(ICoordinateInputEventHandler *opHandler);
        bool SetLock(bool isLock);
        
        //bool SetStyleSheet(const std::wstring &styleSheet);
        //std::wstring GetStyleSheet() const;

    private:
        OwnerPtr<ILineEditDefinition> GetDefinitionImpl();

    private:
        OwnerPtr<ILineEditDefinition> m_opLineEditDefinition;
        ILineEditDefinition *m_pLineEditDefinitionRefer;
        ICoordinateInputEventHandler *m_pEventHandler;
        bool m_isLock;
        std::wstring m_styleSheet;
        bool m_isEditingFinished;
    };
}

